<?php

namespace app\admin\model;

use think\Model;


class VCourse extends Model
{


    // 表名
    protected $name = 'v_course';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_publish_text',
        'media_type_text',
        'is_first_text'
    ];


    public function getIsPublishList()
    {
        return ['0' => __('Is_publish 0'), '1' => __('Is_publish 1')];
    }

    public function getMediaTypeList()
    {
        return ['1' => __('Media_type 1'), '2' => __('Media_type 2')];
    }

    public function getIsFirstList()
    {
        return ['1' => __('Is_first 1'), '0' => __('Is_first 0')];
    }


    public function getIsPublishTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_publish']) ? $data['is_publish'] : '');
        $list = $this->getIsPublishList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getMediaTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['media_type']) ? $data['media_type'] : '');
        $list = $this->getMediaTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsFirstTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_first']) ? $data['is_first'] : '');
        $list = $this->getIsFirstList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    static function getCourse($course_ids)
    {
        return self::where('id', 'in', $course_ids)->column('title', 'id');
    }
}
